/**
 * 
 */
package com.yidu.user.service;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.yidu.model.ManageUser;
import com.yidu.model.Page;
import com.yidu.user.dao.ManageUserMapper;

@Service(value="userService")
public class ManageUserServiceImpl implements ManageUserService{
	@Resource
	private ManageUserMapper userMapper;
	/**
	 * 注册增加用户
	 */
	@Override
	public int insertSelective(ManageUser user) {
		user.setUserId(UUID.randomUUID().toString().replaceAll("-", ""));
		int row = userMapper.insertSelective(user);
		return row;
	}
	/**
	 * 登录验证
	 */
	@Override
	public boolean getCountByUserName(ManageUser user) {
		int row = userMapper.getCountByUserName(user);
		if(row>0){
			return true;
		}else{
			return false;
		}
		
	}
	/**
	 * 查询出所有的用户
	 */
	@Override
	public List<ManageUser> getAllUser(Page page){
		if(page.getPages()==0){
			page.setRows(10);
			page.setPages(1);
		}
		if(page.getTotal()==0){
			page.setTotal(getAllCount());
		}
		List<ManageUser> list = userMapper.getAllUser(page);
		return list;
	}
	/**
	 * 删除用户
	 */
	@Override
	public int deleteByPrimaryKey(String userId) {
		int row = userMapper.deleteByPrimaryKey(userId);
		return row;
	}
	/**
	 * 查找出要修个的信息
	 */
	@Override
	public ManageUser showUpdate(String userId) {
		ManageUser user = userMapper.showUpdate(userId);
		return user;
	}
	/**
	 * 修改和增加
	 */
	@Override
	public int updateByPrimaryKeySelective(ManageUser user) {
		if(!"".equals(user.getUserId())){
			return userMapper.updateByPrimaryKeySelective(user);
		}else{
			user.setUserId(UUID.randomUUID().toString().replaceAll("-", ""));
			return userMapper.insertSelective(user);
		}
	}
	
	@Override
	public int getAllCount() {
		
		return userMapper.getAllCount();
	}
	@Override
	public List<ManageUser> getAllName() {
		
		return userMapper.getAllName();
	}

}
